import React, { useState } from 'react'
import PubSub from 'pubsub-js'
export default function Gege() {
  const [car, setCar] = useState('别摸我')

  
  const changeCar = () => {
    setCar('五菱宝宝')
    //发布
    PubSub.publish('car','五菱宝宝') //发布名字一一对应
    //这里因为setCar是异步的 并不能直接把car发送过去
  }

  return (
    <div>
      <p>我是老大</p>
      <p>我开的车是{car}</p>
      <button onClick={changeCar}>破产了</button>
    </div>
  )
}
